# 清理下载目录
rm -rf ./downloads/

# 获取 APK 路径
if [ -n "$apkSpecificPath" ]; then
    APK_PATH=$(find . -name "*.apk" | grep "$apkSpecificPath" | head -n 1)
else
    APK_PATH=$(find . -name "*.apk" | grep "build/outputs/" | head -n 1)
fi
echo "使用APK路径: $APK_PATH"

# 下载加固脚本
curl -o "reinforce.py" http://git.gxatek.com/-/snippets/185/raw/master/reinforce.py

# APK 加固处理
if [ "${params.commit_changed}" = "true" ]; then
    echo "commit_changed: 执行加固"
    # 加固APK
    python3 reinforce.py --local-apk="$APK_PATH" --reinforce=true
    
    # 覆盖原apk
    cp -f ./downloads/reinforced_*.apk "$APK_PATH"
else
    # commit 相同，不加固
    echo "commit_same: 不执行加固"
    python3 reinforce.py --local-apk="$APK_PATH" --reinforce=false
fi

# 清理下载目录
rm -rf ./downloads/